package com.atguigu.gmall.cart.controller;

import com.atguigu.gmall.cart.service.CartService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.cart.CartItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/9 16:29
 */
@RestController
@RequestMapping("/api/cart")
public class CartController {
    @Autowired
    CartService cartService;
    //api/cart/cartList
    @GetMapping("/cartList")
    public Result<List<CartItem>> cartList(){
        List<CartItem> cartList=cartService.getCartList();

        return Result.ok(cartList);
    }

    ///addToCart/41/-1
    @PostMapping("/addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable("skuId") Long skuId, @PathVariable("skuNum") Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return Result.ok();
    }
    ///checkCart/51/0
    @GetMapping("/checkCart/{skuId}/{check}")
    public Result checkCart(@PathVariable("skuId") Long skuId, @PathVariable("check") Integer check){
        cartService.checkCart(skuId,check);
        return Result.ok();
    }

    @DeleteMapping("deleteCart/{skuId}")
    public Result deleteCart(@PathVariable("skuId") Long skuId){
        cartService.deleteCart(skuId);
        return Result.ok();
    }
    ///checkCartAllToZero/'+isChecked
    @GetMapping("/checkCartAllTo/{isChecked}")
    public Result checkCartAllTo(@PathVariable("isChecked") Integer isChecked){
        cartService.checkCartAllTo(isChecked);
        return Result.ok();
    }
    //'/addCollect/' + skuId
    @PostMapping("/addCollect/{skuId}")
    public Result addCollect(@PathVariable("skuId") Long skuId){
        cartService.addCollect(skuId);
        return Result.ok();
    }
    //取消收藏
    @DeleteMapping("/cancelCollect/{skuId}")
    public Result cancelCollect(@PathVariable("skuId") Long skuId){
        cartService.cancelCollect(skuId);
        return Result.ok();
    }
    //获取收藏列表
    @GetMapping("/collectList")
    public Result<List<CartItem>> collectList(){
        List<CartItem> collectList=cartService.getCollectList();
        return Result.ok(collectList);
    }
    ///removeCollect/' + skuId
    @DeleteMapping("/removeCollect/{skuId}")
    public Result removeCollect(@PathVariable("skuId") Long skuId){
        cartService.removeCollect(skuId);
        return Result.ok();
    }
}
